var { curry } = require("lodash");
var l = console.log;

var match = curry(function (what, str) {
  return str.match(what);
});

//\s代表空格
l(match(/\w/g, "hello world"));
l(match(/\s/g)("hello world"));

var hasSpaces = match(/\s+/g);
//function(x){return x.match(/\s+/g);}

l(hasSpaces("spaceless"));
l(hasSpaces("hello world"));

var replace = curry(function (what, replacement, str) {
  return str.replace(what, replacement);
});

var filter = curry(function (f, arr) {
  return arr.filter(f);
});

var map = curry(function (f, arr) {
  return arr.map(f);
});

l(filter(hasSpaces)(["spaceless", "hello world"]));
l(filter(hasSpaces, ["spaceless", "hello world"]));

var findSpaces = filter(hasSpaces);

l(findSpaces(["spaceless", "hello world"]));

var noFace = replace(/[face]/gi);

var censored = noFace("*");

l(censored("he has no face"));

//这里表明的是一种“预加载”函数的能力
//通过传递一到两个参数调用函数，就能得到一个记住了这些参数的新函数。

//只需传给函数一些参数，就能得到一个新函数。

var getChildren = (x) => x.childNodes;

var allTheChildren = map(getChildren)


